package com.xiaoze.provider.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaoze.api.entity.CourseType;
import com.xiaoze.api.service.CourseTypeService;
import com.xiaoze.provider.mapper.CourseTypeMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

/**
 * CourseTypeServiceImpl
 *
 * @author xiaoze
 * @date 2018/6/3
 *
 */
@DubboService(version = "${demo.service.version}", interfaceClass = CourseTypeService.class)
@Transactional(rollbackFor = Exception.class)
public class CourseTypeServiceImpl implements CourseTypeService {

    @Autowired
    private CourseTypeMapper courseTypeMapper;


    @Override
    public void addCourseType(CourseType courseType) {
        courseTypeMapper.insert(courseType);
    }

    @Override
    public void removeCourseType(Integer typeId) {
        courseTypeMapper.deleteById(typeId);
    }

    @Override
    public void updateCourseType(CourseType courseType) {
        courseTypeMapper.updateById(courseType);
    }

    @Override
    public CourseType getCourseTypeById(Integer typeId) {
        return courseTypeMapper.selectById(typeId);
    }

    @Override
    public Page<CourseType> loadByPageNo(Integer pageNo, Integer pageSize) {
        return courseTypeMapper.selectPage(new Page<>(pageNo, pageSize),
                new LambdaQueryWrapper<CourseType>()
                        .orderByAsc(CourseType::getTypeId)
        );
    }
}
